package com.study.spmongodb.book.wwj.char03;

import java.util.concurrent.TimeUnit;

/**
 * @author MI
 * @version 1.0
 * @date 2020/11/24 19:50
 */
public class InterruptThreadExit {
    /**
     * 关闭线程|捕获中断信号关闭线程
     */
    public static void main(String[] args) throws InterruptedException {
        final Thread thread = new Thread() {
            @Override
            public void run() {
                System.out.println(" i will start work");
                while (!isInterrupted()) {
                    //working
                }
                System.out.println("i will be exiting");
            }
        };

        thread.start();
        TimeUnit.SECONDS.sleep(1);
        System.out.println("system will be shutdown");
        thread.interrupt();
    }
}
